<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link href="/css/common.css" rel="stylesheet" type="text/css" />
<style>
input {width:150px;}
.wrapContent {margin:0 auto;padding:0 30px;}
.center {text-align:center;}
.block {padding:10px 30px;}
.line {border:none;border-bottom:1px solid #666;clear:both;}
.lineHeight{height:34px;line-height:34px;}
.right {text-align:right;width:120px;vertical-align:top}
.errMsg {color:red;margin:0 0 0 5px;}
</style>
</head>
<body>
<div class="wrapContent">
	<div class="block">
		<h2 class="center">添加机器</h2>
		<table style="width:500px;border:none;margin:50px auto 0;" cellpadding="0" cellspacing="0">
			<tr class="lineHeight">
				<td class="right">机器名称：</td>
				<td><input id="name"/><b id="nameErrMsg" class="errMsg">*</b></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号1：</td>
				<td><input name="type"/><b id="typeErrMsg" class="errMsg">*</b></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号2：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号3：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号4：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号5：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号6：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号7：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号8：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号9：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号10：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号11：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号12：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号13：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号14：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号15：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号16：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号17：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号18：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号19：</td>
				<td><input name="type"/></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">硒鼓型号20：</td>
				<td><input name="type"/></td>
			</tr>
		</table>
	</div>
	<div class="center">
		<input id="submit" type="button" class="submitBtn" value="确定"/>
	</div>
</div>
</body>
<script src="/js/lib.min.js" type="text/javascript"></script>
<script src="/js/md5.min.js" type="text/javascript"></script>
<script type="text/javascript">
var nameInput = $('#name'),
	nameErrMsg = $('#nameErrMsg'),
	typeInputs = document.getElementsByName('type'),
	typeErrMsg = $('#typeErrMsg'),
	submitBtn = $('#submit');
	
submitBtn.attr({onclick:function(){
	var checkFlag = true;
	var name = $.trim(nameInput.val());
	if (!name) {
		nameErrMsg.html('请输入机器名称');
		checkFlag && nameInput[0].focus();
		checkFlag = false;
	}else {
		nameErrMsg.html('*');
	}
	
	var types = [];
	for(var i=0, typeInput; typeInput=typeInputs[i++];) {
		if (i==1 && $.trim(typeInput.value)==''){
			typeErrMsg.html('请输入硒鼓型号');
			checkFlag && typeInput.focus();
			checkFlag = false;
			break;
		}
		types.push($.trim(typeInput.value));
	}
	
	if (!checkFlag) return ;
	
	submitBtn.val('正在处理，请稍后...');
	submitBtn[0].disabled = true;
	
	$.ajax({
		url:'/admin/machine.php?op=doAdd',
		data:{'name':name, 'types':types},
		type:'POST',
		callback:function(res){
			alert(res.errmsg);
			submitBtn.val('确定');
			submitBtn[0].disabled = false;
			if (res.errno == '0'){
				nameInput.val('');
				nameErrMsg.html('*');
				typeErrMsg.html('*');
				for(var i=0, typeInput; typeInput=typeInputs[i++];) {
					typeInput.value='';
				}
			}
		}
	});
	
}});
</script>
</html>